package com.climb.ssm.controller;

import com.climb.ssm.service.AccountService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/**
 * @author Administrator
 * 使用spring-ioc的方法去执行client1的操作
 *ioc也是一种设计思想,在client中实际上也是ioc的实现
 */
public class Client_Ioc {
    public static void main(String[] args) {
        //获取springioc容器,并根据id获取对象
//        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        /*ApplicationContext没有close方法*/
        /*在主配置文件里不import在这直接引入不同的配置文件,用逗号隔开*/
//        ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml","applicationContext2.xml");
        /*在配置文件里面import了子配置文件或者直接在主配置文件中已经注册了需要的bean对象*/
/*        ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
        AccountService service=context.getBean("accountService",AccountService.class);
        service.saveAccount();
        System.out.println(service);
        context.close();*/
            /*BeanFactory延迟加载 F9*/
        Resource resource = new ClassPathResource("applicationContext.xml");
        BeanFactory factory = new XmlBeanFactory(resource);
//        BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
        AccountService as = (AccountService)factory.getBean("accountService");
        System.out.println(as);








    }
}